package com.lee9213.conference.track.management;

import com.lee9213.conference.track.management.comparator.TalkEntityComparator;
import com.lee9213.conference.track.management.constant.Constant;
import com.lee9213.conference.track.management.entity.Conference;
import com.lee9213.conference.track.management.entity.TalkEntity;
import com.lee9213.conference.track.management.entity.TrackEntity;
import com.lee9213.conference.track.management.format.Parse;
import com.lee9213.conference.track.management.format.TalkParse;
import com.lee9213.conference.track.management.handler.*;
import com.lee9213.conference.track.management.util.FileUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 主程序入口
 *
 * @author lee9213@163.com
 * @version 1.0
 * @date 2018-07-11 10:38
 */
public class Application {

    public static void main(String[] args) {

        // 解析输入文件
        List<String> textList = null;
        try {
            textList = FileUtil.readFile(Constant.FILE_NAME);
        } catch (Exception e) {
            e.printStackTrace();
        }

        Parse parse = new TalkParse();
        List<TalkEntity> allTalkEntities = parse.parse(textList);
        allTalkEntities.sort(TalkEntityComparator.getInstance()::compare);

        System.out.println("Test input: ");
        allTalkEntities.forEach(talkEntity -> System.out.printf("%s %s %s %n", talkEntity.getTitle(), talkEntity.getMinutes(), talkEntity.getTalkType()));
        System.out.println();

        // 组装会话
        List<TrackEntity> trackEntities = new ArrayList<>();
        TrackEntity trackEntity;
        FilterChain filterChain;
        while (allTalkEntities.size() > 0) {
            trackEntity = new TrackEntity();
            filterChain = new FilterChain();
            filterChain.addFilter(new MorningFilter()).addFilter(new LunchFilter()).addFilter(new AfternoonFilter()).addFilter(new NetworkingFilter());
            filterChain.doFilter(allTalkEntities, trackEntity);
            trackEntities.add(trackEntity);
        }

        System.out.println("Test output: ");
        // 输出会话
        Conference conference = new Conference(trackEntities);
        conference.output();

    }
}
